using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class GroupController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public GroupController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertGroup(GroupInfo oi)
		{
            return DataProvider.InsertGroup(oi.ConfigurationId, oi.Name);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdateGroup(GroupInfo oi) 
		{
			return DataProvider.UpdateGroup(oi.GroupId, oi.ConfigurationId, oi.Name);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeleteGroup(Guid groupId)
		{
			return DataProvider.DeleteGroup(groupId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public GroupInfo SelectGroup(Guid groupId)
        {    
			return ObjectFromDataRow(DataProvider.SelectGroup(groupId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<GroupInfo> SelectGroups()
		{
            return ListFromDataTable(DataProvider.SelectGroups());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<GroupInfo> SelectGroups(string sortExpression)
        {
            List<GroupInfo> retList = SelectGroups();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new GroupComparer(sortExpression));
            }
            return retList;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<GroupInfo> SelectGroupsByConfiguration(Guid configurationId)
		{
			return ListFromDataTable(DataProvider.SelectGroupsByConfiguration(configurationId));
		}
		
        public List<GroupInfo> SelectGroupsByConfiguration(Guid configurationId,string sortExpression)
		{
			List<GroupInfo> retList = SelectGroupsByConfiguration(configurationId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new GroupComparer(sortExpression));
            }
            return retList;
		}

	}

}
		